package com.tianji.learning.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.common.domain.query.PageQuery;

import com.tianji.learning.domain.dto.LearningPlanDTO;
import com.tianji.learning.domain.vo.LearningLessonVO;
import com.tianji.learning.domain.vo.LearningPlanPageVO;
import com.tianji.learning.service.ILearningLessonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.hibernate.validator.resourceloading.PlatformResourceBundleLocator;
import org.springframework.amqp.rabbit.connection.PublisherCallbackChannelImpl;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 学生课程表 前端控制器
 * </p>
 *
 * @author ming
 * @since 2025-04-17
 */
@RestController
@RequestMapping("/lessons")
@RequiredArgsConstructor //为final/@NonNull修饰的字段生成有参构造方法
@Api(tags = "我的课表相关接口")
public class LearningLessonController {

    private final ILearningLessonService lessonService;

    @GetMapping("/page")
    @ApiOperation("分页查询我的课表")
    public PageDTO<LearningLessonVO> queryMyLesson(PageQuery pageQuery) {
        return lessonService.queryMyLesson(pageQuery);
    }

    @GetMapping("/now")
    @ApiOperation("查询最近学习的课程")
    public LearningLessonVO queryLeastLearning() {
        return lessonService.queryLeastLearning();
    }

    @DeleteMapping("{courseId}")
    @ApiOperation("根据课程id删除课表中的课程")
    public void deleteByCourseId(@PathVariable Long courseId) {
        lessonService.deleteByCourseId(null, courseId);
    }

    @GetMapping("{courseId}/valid")
    @ApiOperation("根据课程id查询课程是否有效")
    public Long validCourseById(@PathVariable Long courseId) {
        return lessonService.validCourseById(courseId);
    }

    @GetMapping("{courseId}")
    @ApiOperation("根据课程id查询课表信息")
    public LearningLessonVO getLessonByCourseId(@PathVariable Long courseId) {
        return lessonService.getLessonByCourseId(courseId);
    }

    @PostMapping("/plan")
    @ApiOperation("创建/修改学习计划")
    public void updateLearningPlan(@RequestBody LearningPlanDTO learningPlanDTO) {
        lessonService.updateLearningPlan(learningPlanDTO);
    }

    @GetMapping("/plans")
    @ApiOperation("查询我的学习计划")
    public LearningPlanPageVO queryLearningPlan(PageQuery pageQuery){
        return lessonService.queryLearningPlan(pageQuery);
    }

}
